package com.canxi.games.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.canxi.common.annotation.RepeatSubmit;
import com.canxi.common.annotation.Log;
import com.canxi.common.core.controller.BaseController;
import com.canxi.common.core.domain.PageQuery;
import com.canxi.common.core.domain.R;
import com.canxi.common.core.validate.AddGroup;
import com.canxi.common.core.validate.EditGroup;
import com.canxi.common.enums.BusinessType;
import com.canxi.common.utils.poi.ExcelUtil;
import com.canxi.games.domain.vo.CxGamesConfigVo;
import com.canxi.games.domain.bo.CxGamesConfigBo;
import com.canxi.games.service.ICxGamesConfigService;
import com.canxi.common.core.page.TableDataInfo;

/**
 * 游戏配置
 *
 * @author ruoyi
 * @date 2024-08-18
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/games/gamesConfig")
public class CxGamesConfigController extends BaseController {

    private final ICxGamesConfigService iCxGamesConfigService;

    /**
     * 查询游戏配置列表
     */
    @SaCheckPermission("games:gamesConfig:list")
    @GetMapping("/list")
    public TableDataInfo<CxGamesConfigVo> list(CxGamesConfigBo bo, PageQuery pageQuery) {
        return iCxGamesConfigService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出游戏配置列表
     */
    @SaCheckPermission("games:gamesConfig:export")
    @Log(title = "游戏配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(CxGamesConfigBo bo, HttpServletResponse response) {
        List<CxGamesConfigVo> list = iCxGamesConfigService.queryList(bo);
        ExcelUtil.exportExcel(list, "游戏配置", CxGamesConfigVo.class, response);
    }

    /**
     * 获取游戏配置详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("games:gamesConfig:query")
    @GetMapping("/{id}")
    public R<CxGamesConfigVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iCxGamesConfigService.queryById(id));
    }

    /**
     * 新增游戏配置
     */
    @SaCheckPermission("games:gamesConfig:add")
    @Log(title = "游戏配置", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody CxGamesConfigBo bo) {
        return toAjax(iCxGamesConfigService.insertByBo(bo));
    }

    /**
     * 修改游戏配置
     */
    @SaCheckPermission("games:gamesConfig:edit")
    @Log(title = "游戏配置", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody CxGamesConfigBo bo) {
        return toAjax(iCxGamesConfigService.updateByBo(bo));
    }

    /**
     * 删除游戏配置
     *
     * @param ids 主键串
     */
    @SaCheckPermission("games:gamesConfig:remove")
    @Log(title = "游戏配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iCxGamesConfigService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    /**
     * 获取游戏配置详细信息,根据用户ID，获取配置信息
     *
     * @param id 主键
     */
    @SaCheckPermission("games:gamesConfig:query")
    @GetMapping("/getConfigByUsername")
    public R<CxGamesConfigVo> getConfigByUserId(CxGamesConfigBo bo) {

        return R.ok(iCxGamesConfigService.getConfigByUserId(bo));
    }

    /**
     * 获取游戏关卡数据
     */



}
